package com.lagou.service.impl;

import com.lagou.pojo.Article;
import com.lagou.repository.ArticleRepository;
import com.lagou.service.ArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.stereotype.Service;

/**
 * @author srh
 * @date 2020/03/26
 **/
@Service(value = "articleService")
public class ArticleServiceImpl implements ArticleService {

    @Autowired
    private ArticleRepository articleRepository;

    @Override
    public Page<Article> queryPage(Integer currentPage) {
        Sort.Order order = new Sort.Order(Sort.Direction.DESC, "id");
        PageRequest pageInfo = PageRequest.of(currentPage - 1, DEFAULT_SIZE, Sort.by(order));
        return articleRepository.findAll(pageInfo);
    }
}
